package com.lyh.nacosconfig9001.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author liyanhao
 * @Date 2022-12-08 16:41
 */
@RestController
@RequestMapping("/config")
@RefreshScope
public class ConfigController {
    @Value("${useLocalCache:false}")
    private boolean useLocalCache;

    @Value("${myAppName:zhangsan}")
    private String myAppName;

    @RequestMapping("/get")
    public boolean get() {
        return useLocalCache;
    }
    @RequestMapping("/getApp")
    public String getApp() {
        return myAppName;
    }



    @Value("{common.age}")
    String age;
    @Value("{common.name}")
    String name;

    @GetMapping("/common")
    public String hello(){
        return name + "," + age;
    }
    //触发@refreshScope执行逻辑会导致@Scheduled定时任务失败
    @Scheduled(cron ="*/3 * * * * ?")
    public void execute(){
        System.out.println("定时任务正在执行.......");    }
}
